/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool findTarget(TreeNode* root, int k) {
        vector<int> ans;
        inorder(root,ans);
        int l=0,r=ans.size()-1;
        while(l<r){
            if(ans[l]+ans[r]==k){return true;}
            if(ans[l]+ans[r]<k){l++;}
            if(ans[l]+ans[r]>k){r--;}
        }
        return false;
    }
    void inorder(TreeNode* root,vector<int>& ans){
        if(root==nullptr){return;}
        inorder(root->left,ans);
        ans.push_back(root->val);
        inorder(root->right,ans);
    }
};